#define  _CRT_SECURE_NO_WARNINGS 1
#include "heap.h"

void swap(HPDataType* a, HPDataType* b)
{
	HPDataType temp = *a;
	*a = *b;
	*b = temp;
}


void adjustup(HPDataType* a, int child)
{
	assert(a);
	int parent = (child - 1) / 2;
	while (child)
	{
		if (a[child] > a[parent])
		{
			swap(&a[child],&a[parent]);
		}
		else
		{
			break;
		}
		child = parent;
		parent = (parent - 1) / 2;
	}
}

void adjustdown(HPDataType* a, int n, int parent)
{
	assert(a);
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (child + 1 < n && a[child] < a[child + 1])
		{
			child++;
		}
		if (a[child] > a[parent])
		{
			swap(&a[child], &a[parent]);
		}
		parent = child;
		child = child * 2 + 1;
	}
}

